#pragma once
#include "DXAMLCommon.h"
#include "IObject.h"
#include "xchainedmap.h"

class CEventManager;
class CFocusManager;
class VisualTree;
class CUIElement;
class CDependencyObject;
class CDMViewport;
class CDMCViewport;
class CPointer;
class CEventArgs;


class CInputManager :
	public IObject
{

	/*
	public: static HRESULT Create(CInputManager * * ppInputManager, struct ICoreServices * pCoreService, CEventManager * pEventManager, CFocusManager * pFocusManager, VisualTree * pVisualTree);
	public: virtual XUINT32 AddRef();
	public: virtual XUINT32 Release();
	public: virtual HRESULT ProcessInput(struct InputMessage * pMsg, XINT32 * handled, unsigned long hWindowID);
	public: virtual HRESULT ProcessDragDrop(struct DragMsg * pMsg, XUINT32 bRequireMouseMoveForDragOver, XUINT32 bRaiseSync, XINT32 * handled, unsigned long hWindowID);
	public: virtual HRESULT ProcessDragDrop(struct DragMsg * pMsg, XINT32 * handled, unsigned long hWindowID);
	public: virtual HRESULT ProcessTouchInteractionCallback(struct IDependencyObject * pElement, struct TouchInteractionMsg * pMsg);
	public: HRESULT ProcessManipulationInertiaInteraction();
	public: HRESULT RegisterDMViewportsOnPointerDown(XUINT32 pointerId, CUIElement * pPointedElement);
	public: HRESULT UnRegisterDMViewportsOnPointerUp(XUINT32 pointerId);
	public: HRESULT NotifyFocusChanged(struct IDependencyObject * pFocusedElement, XUINT32 bringIntoView);
	public: HRESULT ProcessInputPaneShowing();
	public: XUINT32 IsTextEditableControl(CDependencyObject * pObject);
	public: XUINT32 CanUseInputPane(CDependencyObject * pObject);
	public: HRESULT ProcessUIThreadTick();
	public: HRESULT RegisterDirectManipulationContainer(CUIElement * pDMContainer, XUINT32 fIsDirectManipulationContainer);
	public: HRESULT RegisterDirectManipulationCrossSlideContainer(CUIElement * pDMCrossSlideContainer, XUINT32 fIsDirectManipulationCrossSlideContainer);
	public: HRESULT DirectManipulationCrossSlideContainerCompleted(CUIElement * pDMCrossSlideContainer);
	private: HRESULT ProcessDirectManipulationViewportStatusUpdate(CDMViewport * pViewport, enum XDMViewportStatus oldStatus, enum XDMViewportStatus newStatus, XUINT32 fIsValuesChangePreProcessing, XUINT32 * pfManipulationCompleted);
	public: HRESULT ProcessDirectManipulationViewportStatusUpdate(CDMViewport * pViewport, enum XDMViewportStatus oldStatus, enum XDMViewportStatus newStatus);
	public: HRESULT GetDirectManipulationViewports(XUINT32 fReturnAllActiveViewports, xvector<CDMCViewport *> & compositorViewports);
	public: HRESULT GetOldDirectManipulationViewport(struct IObject * * ppCompositorViewport);
	public: HRESULT NotifyReleaseManipulationContainer(CUIElement * pDMContainer);
	public: HRESULT NotifyCanManipulateElements(CUIElement * pDMContainer, XUINT32 fCanManipulateElementsByTouch, XUINT32 fCanManipulateElementsNonTouch);
	public: HRESULT NotifyManipulatableElementChanged(CUIElement * pDMContainer, CUIElement * pOldManipulatableElement, CUIElement * pNewManipulatableElement);
	public: HRESULT NotifyViewportChanged(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XUINT32 fInManipulation, XUINT32 fBoundsChanged, XUINT32 fTouchConfigurationChanged, XUINT32 fNonTouchConfigurationChanged, XUINT32 fConfigurationsChanged, XUINT32 fChainedMotionTypesChanged);
	public: HRESULT UpdateManipulationViewport(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XUINT32 fUpdateBounds, XUINT32 fUpdateInputTransform, XUINT32 fUpdateTouchConfiguration, XUINT32 fUpdateNonTouchConfiguration, XUINT32 fUpdateConfigurations, XUINT32 fUpdateChainedMotionTypes, XUINT32 fActivateTouchConfiguration, XUINT32 fActivateNonTouchConfiguration, XUINT32 fActivateBringIntoViewConfiguration);
	public: HRESULT NotifyPrimaryContentChanged(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XUINT32 fInManipulation, XUINT32 fLayoutRefreshed, XUINT32 fBoundsChanged, XUINT32 fHorizontalAlignmentChanged, XUINT32 fVerticalAlignmentChanged, XUINT32 fZoomFactorBoundaryChanged);
	public: HRESULT UpdateManipulationPrimaryContent(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XUINT32 fUpdateLayoutRefreshed, XUINT32 fUpdateBounds, XUINT32 fUpdateHorizontalAlignment, XUINT32 fUpdateVerticalAlignment, XUINT32 fUpdateZoomFactorBoundary);
	public: HRESULT NotifyPrimaryContentTransformChanged(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XUINT32 fInManipulation, XUINT32 fTranslationXChanged, XUINT32 fTranslationYChanged, XUINT32 fZoomFactorChanged);
	public: HRESULT UpdateManipulationPrimaryContentTransform(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XUINT32 fInManipulation, XUINT32 fUpdateTranslationX, XUINT32 fUpdateTranslationY, XUINT32 fUpdateZoomFactor);
	public: HRESULT NotifySnapPointsChanged(CUIElement * pDMContainer, CUIElement * pManipulatedElement, enum XDMMotionTypes motionType);
	public: HRESULT UpdateManipulationSnapPoints(CUIElement * pDMContainer, CUIElement * pManipulatedElement, enum XDMMotionTypes motionType);
	public: HRESULT NotifyManipulatedElementAlignmentChanged(CUIElement * pManipulatedElement, XUINT32 fIsForHorizontalAlignment);
	public: HRESULT GetPrimaryContentTransform(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XFLOAT & translationX, XFLOAT & translationY, XFLOAT & zoomFactor);
	public: HRESULT BringIntoViewport(CUIElement * pDMContainer, CUIElement * pManipulatedElement, struct XRECTF_WH & bounds, XUINT32 fAnimate);
	public: HRESULT GetDirectManipulationTransform(CUIElement * pManipulatedElement, XUINT32 fIsForCompositorTreeNode, XUINT32 & fTransformSet, XFLOAT & translationX, XFLOAT & translationY, XFLOAT & zoomFactor, XFLOAT & offsetX, XFLOAT & offsetY, XFLOAT & offsetZoomX, XFLOAT & offsetZoomY);
	public: HRESULT CreateDirectManipulationContentsMap(xchainedmap<CUIElement *,IObject *> * * ppMapUIElementToCompositorContent);
	public: HRESULT CompleteDirectManipulation(CDMViewport * pViewport, XUINT32 fDisableViewport);
	public: HRESULT ProcessInputMessageWithDirectManipulation(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XUINT32 & fHandled);
	public: HRESULT SetConstantVelocities(CUIElement * pDMContainer, CUIElement * pManipulatedElement, XFLOAT panXVelocity, XFLOAT panYVelocity);
	public: HRESULT SetPointerCapture(struct IDependencyObject * pObject, CPointer * pPointer, XUINT32 * pResult);
	public: HRESULT ReleasePointerCapture(struct IDependencyObject * pObject, CPointer * pPointer);
	public: HRESULT ReleaseAllPointerCaptures(struct IDependencyObject * pObject);
	public: HRESULT ReleasePointerCaptureById(XINT32 releasePointerId);
	public: HRESULT SetCursor(enum MouseCursor eMouseCursor);
	public: HRESULT UpdateCursor(XINT32 bUnset);
	public: HRESULT DestroyInputPaneHandler();
	public: void Reset();
	public: HRESULT CleanPointerElementObject(CDependencyObject * pObject);
	public: HRESULT SetVisualTree(VisualTree * pVisualTree);
	public: struct IXcpInputPaneHandler * GetInputPaneHandler();
	public: HRESULT DestroyInteractionEngine(CUIElement * pDestroyElement);
	private: ~CInputManager();

	private: CInputManager(struct ICoreServices * pCoreService, CEventManager * pEventManager, CFocusManager * pFocusManager, VisualTree * pVisualTree);
	private: CInputManager();
	private: void Init(struct ICoreServices * pCoreService, CEventManager * pEventManager, CFocusManager * pFocusManager, VisualTree * pVisualTree);
	private: virtual HRESULT ProcessPointerInput(struct InputMessage * pMsg, XINT32 * pfHandled, unsigned long hWindowID);
	private: virtual HRESULT ProcessGestureInput(struct IDependencyObject * pElement, struct TouchInteractionMsg * pMsg);
	private: virtual HRESULT ProcessManipulationStartedInput(struct IDependencyObject * pElement, struct TouchInteractionMsg * pMsg);
	private: virtual HRESULT ProcessManipulationDeltaInput(struct IDependencyObject * pElement, struct TouchInteractionMsg * pMsg);
	private: virtual HRESULT ProcessManipulationCompletedInput(struct IDependencyObject * pElement, struct TouchInteractionMsg * pMsg);
	private: HRESULT ProcessEnterLeave(struct IDependencyObject *, CEventArgs *, XINT32);
	private: HRESULT ProcessDragEnterLeave(struct IDependencyObject * pCurrentDragOverElement, CEventArgs * pArgs, XINT32 bSkipLeave, struct XPOINTF xp, XUINT32 bRaiseSync);
	private: HRESULT ProcessCaptureEnterLeave(struct IDependencyObject *, CEventArgs *);
	private: virtual HRESULT ProcessKeyboardInput(struct InputMessage * pMsg, XINT32 * handled);
	private: virtual HRESULT ProcessFocusInput(struct InputMessage * pMsg, XINT32 * handled);
	private: virtual HRESULT SetModifierKeys(struct InputMessage * pMsg, CKeyEventArgs * pArgs);
	private: virtual HRESULT TranslateAppCommandToMediaCommand(enum XAPPCOMMAND eXAppCommand, enum XMEDIACOMMAND * eXMediaCommand);
	private: HRESULT RaiseCharacterReceivedEvent(struct InputMessage * pMsg, XINT32 * handled);
	private: HRESULT RaiseManipulationStartingEvent(CUIElement * pElement, XUINT32 * puiManipulationMode, struct XPOINTF * pPointPivotCenter, XFLOAT * pfPivotRadius);
	private: HRESULT RaiseManipulationInertiaStartingEvent(CUIElement * pElement, struct TouchInteractionMsg * pMsg);
	private: HRESULT GetManipulationElement(CUIElement * pContactElement, CUIElement * * ppManipulationElement);
	private: HRESULT SetPointerFromPointerMessage(struct InputMessage * pMsg, CPointerEventArgs * pPointerArgs);
	private: HRESULT SetPointerKeyModifiers(struct InputMessage * pMsg, CPointerEventArgs * pPointerArgs);
	private: HRESULT IsInteractionSupported(CUIElement * pContactElement, CUIElement * * ppInteractionElement, XUINT32 * pbInteractionSupported);
	private: HRESULT AddPointerIdToInteractionElement(XUINT32 pointerId, CUIElement * pContactElement);
	private: HRESULT RemovePointerIdFromInteractionElement(XUINT32 pointerId);
	private: HRESULT CleanPointerProcessingState(struct InputMessage * pMsg, XUINT32 pointerId, CPointerState * pPointerState, struct IDependencyObject * pDOContact, unsigned long hWindowID);
	private: HRESULT StopInteraction(CUIElement * pContactElement);
	private: HRESULT ProcessInteractionPointerMessages(XUINT32 pointerId, struct InputMessage * pMsg);
	private: HRESULT ProcessPointerMessagesWithInteractionEngine(XUINT32 pointerId, struct InputMessage * pMsg, CUIElement * pInteractionElement, CUIElement * pManipulationElement, XUINT32 bIgnoreManipulationElement, struct IPALTouchInteraction * pInteractionContext, XUINT32 bForceDisableGesture);
	private: HRESULT RaiseManipulationInertiaProcessingEvent();
	private: HRESULT GetInteractionEngine(CUIElement * pInteractionElement, CUIElement * pActiveInteractionElement, XUINT32 fManipulationOnly, struct IPALTouchInteraction * * ppTouchInteraction);
	private: HRESULT ProcessPointerEnterLeave(struct IDependencyObject * pContactElement, struct IDependencyObject * pPointerEnterDO, XUINT32 pointerId, CPointerEventArgs * pArgs, XINT32 bSkipLeave, XUINT32 bForceRaisePointerEntered);
	private: HRESULT ProcessPointerLeave(struct IDependencyObject * pContactElement, XUINT32 pointerId, CPointerEventArgs * pPointerArgs);
	private: void DestroyPointerObjects();
	private: HRESULT CreateLostPointerCaptureEventArgs(struct IDependencyObject * pSenderObject, struct XPOINTF pointLast, CPointer * pPointer, CPointerEventArgs * * ppPointerEventArgs);
	private: HRESULT ProcessPointerCaptureEnterLeave(struct IDependencyObject * pContactElement, struct IDependencyObject * pPointerEnterDO, struct IDependencyObject * pPointerCaptureDO, XUINT32 pointerId, CPointerEventArgs * pArgs);
	private: XUINT32 HasPointerEnter(CDependencyObject * pElement, XUINT32 uiPointerId);
	private: HRESULT SetPointerEnter(CDependencyObject * pElement, XUINT32 uiPointerId, XUINT32 bValue);
	private: HRESULT RemovePointerEnter(CDependencyObject * pElement, XUINT32 uiPointerId);
	private: XUINT32 IsInputPointerNodeDirty(CDependencyObject * pElement, XUINT32 uiPointerId);
	private: HRESULT SetInputPointerNodeDirty(CDependencyObject * pElement, XUINT32 uiPointerId, XUINT32 bValue);
	private: HRESULT RemoveInputPointerNodeDirty(CDependencyObject * pElement, XUINT32 uiPointerId);
	private: XFLOAT ConvertPixelsToDips(XFLOAT pixelValue);
	private: XFLOAT ConvertDipsToPixels(XFLOAT dipsValue);
	private: HRESULT ConvertTransformPointToLocal(CUIElement * pUIElement, struct XPOINTF * ppt);
	private: HRESULT ConvertTransformPointToGlobal(CUIElement * pUIElement, struct XPOINTF * ppt);
	private: HRESULT RaiseRightTappedEventFromKeyUpEvent(CKeyEventArgs * pKeyEventArgs);
	private: HRESULT CreateInputPaneHandler();
	private: HRESULT RegisterInputPaneHandler(void * hWnd);
	private: HRESULT UnregisterInputPaneHandler();
	private: HRESULT RaiseDelayedPointerUpEvent(struct TouchInteractionMsg * pMsgGesture, struct IDependencyObject * pElement);
	private: HRESULT RaiseRightTappedUnhandledEvent(struct TouchInteractionMsg * pMsg, struct IDependencyObject * pElement);
	private: XUINT32 IsElementInViewport(CUIElement *, CDMViewport *);
	private: static XUINT32 IsViewportActive(enum XDMViewportStatus status);
	private: XUINT32 CanDMContainerInitialize();
	private: HRESULT InitializeDirectManipulationContainer(CUIElement * pDMContainer);
	private: HRESULT InitializeDirectManipulationCrossSlideContainer(CUIElement *);
	private: HRESULT UpdateCrossSlideViewportConfigurations(XUINT32 pointerId, CDMViewport * pViewport);
	private: HRESULT StartDirectManipulationCrossSlideContainer(CUIElement * pDMCrossSlideContainer, enum XDMConfigurations parentViewportConfiguration, enum XDMConfigurations parentViewportsCombinedConfigurations);
	private: HRESULT StartDirectManipulationCrossSlideContainers();
	private: HRESULT CompleteDirectManipulationCrossSlideContainers();
	private: HRESULT InitializeDirectManipulationContainers();
	private: HRESULT InitializeDirectManipulationViewportValues(CUIElement * pManipulatedElement, CDMViewport * pViewport, struct IPALDirectManipulationService * pDirectManipulationService);
	private: HRESULT EnsureViewports();
	private: HRESULT EnsureCrossSlideViewports();
	private: HRESULT GetCrossSlideViewport(CUIElement * pDMCrossSlideContainer, CDMCrossSlideViewport * * ppCrossSlideViewport);
	private: HRESULT GetViewport(CUIElement * pManipulatedElement, CDMViewport * * ppViewport);
	private: HRESULT FilterChainedMotions(enum XDMConfigurations configuration, enum XDMMotionTypes & chainedMotionTypes);
	private: HRESULT HasChainingChildViewport(CDMViewport * pViewport, XUINT32 fCheckState, XUINT32 & fHasChainingChildViewport);
	private: HRESULT CompleteParentViewports(CDMViewport * pViewport);
	private: HRESULT EnsureDMServices();
	private: HRESULT GetDMService(CUIElement * pDMContainer, struct IPALDirectManipulationService * * ppDirectManipulationService);
	private: HRESULT UnregisterCrossSlideViewportContactId(XUINT32 pointerId);
	private: HRESULT UnregisterContactId(XUINT32 pointerId, CDMViewport * pExclusiveViewport, XUINT32 fCompleteManipulation);
	private: HRESULT UnregisterCrossSlideViewport(CDMCrossSlideViewport * pCrossSlideViewport);
	private: HRESULT UnregisterViewport(CDMViewport * pViewport);
	private: HRESULT EnableViewport(struct IPALDirectManipulationService * pDirectManipulationService, CDMViewport * pViewport);
	private: HRESULT InitializeDirectManipulationOnPointerDown(XUINT32 pointerId, CUIElement * pPointedElement);
	private: HRESULT SetDirectManipulationContactOnPointerDown(XUINT32 pointerId, CDependencyObject * pPointedElement, CUIElement * pChildElement, CUIElement * pDMContainer);
	private: HRESULT SetDirectManipulationCrossSlideContainerOnPointerDown(XUINT32 pointerId, CUIElement * pDMCrossSlideContainer);
	private: HRESULT AddCrossSlideViewportContactId(XUINT32 pointerId, CDMCrossSlideViewport * pCrossSlideViewport);
	private: HRESULT SetupDirectManipulationViewport(CUIElement * pDMContainer, CUIElement * pManipulatedElement, CDMViewport * pViewport, struct IDirectManipulationContainer * pDirectManipulationContainer, struct IPALDirectManipulationService * pDirectManipulationService, XUINT32 fIsForTouch, XUINT32 fIsForBringIntoViewport, XUINT32 fIsForFullSetup);
	private: HRESULT DisableViewport(CUIElement * pDMContainer, CUIElement * pManipulatedElement);
	private: HRESULT GetDirectManipulationViewportEventHandler(struct IXcpDirectManipulationViewportEventHandler * * ppDirectManipulationViewportEventHandler);
	private: HRESULT DeleteDMViewports();
	private: HRESULT DeleteDMCrossSlideViewports();
	private: HRESULT DeleteDMServices();
	private: HRESULT DeleteDMContainersNeedingInitialization();
	private: HRESULT UpdateDirectManipulationManagerActivation(CUIElement * pDMContainer, XUINT32 fRefreshViewportStatus);
	private: HRESULT UpdateDirectManipulationManagerActivation(CUIElement * pDMContainer, XUINT32 fCancelManipulations, XUINT32 fCanManipulateElements, XUINT32 fRefreshViewportStatus);
	private: HRESULT UpdateManipulationConfigurations(struct IPALDirectManipulationService * pDirectManipulationService, CDMViewport * pViewport, XUINT32 cConfigurations, enum XDMConfigurations * pConfigurations);
	private: HRESULT UpdateManipulationTouchConfiguration(struct IPALDirectManipulationService * pDirectManipulationService, CDMViewport * pViewport, enum XDMConfigurations touchConfiguration);
	private: HRESULT UpdateManipulationNonTouchConfiguration(struct IPALDirectManipulationService * pDirectManipulationService, CDMViewport * pViewport, enum XDMConfigurations nonTouchConfiguration);
	private: HRESULT UpdateBringIntoViewportConfiguration(struct IPALDirectManipulationService * pDirectManipulationService, CDMViewport * pViewport, enum XDMConfigurations bringIntoViewportConfiguration);
	private: HRESULT ProcessDirectManipulationViewportChanges(CDMViewport * pViewport);
	private: HRESULT ProcessDirectManipulationViewportChanges();
	private: HRESULT ProcessConstantVelocityViewportStatusUpdate(CDMViewport * pViewport, enum XDMViewportStatus currentStatus);
	private: HRESULT ProcessDirectManipulationViewportValuesUpdate(CDMViewport * pViewport, XUINT32 fIsInertial, XUINT32 fIsLastDelta);
	private: HRESULT DeclareNewViewportForCompositor(CDMViewport * pViewport, struct IDirectManipulationContainer * pDirectManipulationContainer);
	private: HRESULT SetDirectManipulationHandlerWantsNotifications(CDMViewport * pViewport, CUIElement * pManipulatedElement, struct IDirectManipulationContainer * pDirectManipulationContainer, XUINT32 fWantsNotifications);
	private: HRESULT RefreshDirectManipulationHandlerWantsNotifications();
	private: HRESULT RequestAdditionalFrame();
	private: CCoreServices * m_pCoreService;
	private: CEventManager * m_pEventManager;
	private: CFocusManager * m_pFocusManager;
	private: VisualTree * m_pVisualTree;
	private: CDependencyObject * m_pDragEnterDO;
	private: CDependencyObject * m_pTextCompositionTargetDO;
	private: XINT32 m_xMousePosLast;
	private: XINT32 m_yMousePosLast;
	private: struct XPOINTF m_ptStylusPosLast;
	private: XFLOAT m_fStylusPressureFactorLast;
	private: enum XDeviceType m_xDeviceTypeOnDown;
	private: XUINT32 m_bStylusInvertedOnDown;
	private: enum MouseCursor m_eCurrentMouseCursor;
	private: XUINT32 m_cRef;
	private: XINT32 m_fMouseDown;
	private: XINT32 m_fSawMouseLeave;
	private: XUINT32 m_fKeyDownHandled;
	private: xchainedmap<unsigned int,CUIElement *> m_mapInteraction;
	private: xchainedmap<CUIElement *,CUIElement *> m_mapManipulationContainer;
	private: xchainedmap<unsigned int,CPointerState *> m_mapPointerState;
	private: xchainedmap<CDependencyObject *,xchainedmap<unsigned int,unsigned int> *> m_mapPointerEnterFromElement;
	private: xchainedmap<CDependencyObject *,xchainedmap<unsigned int,unsigned int> *> m_mapPointerNodeDirtyFromElement;
	private: CInteractionManager * m_pInteractionManager;
	private: struct IXcpInputPaneHandler * m_pInputPaneHandler;
	private: struct IPALInputPaneInteraction * m_pInputPaneInteraction;
	private: CContentControl * m_pRegisteredRootScrollViewer;
	private: CorePeggedPtr<CPointerEventArgs> m_pPendingPointerEventArgs;
	private: void * m_hCoreWindow;
	private: xvector<CDMViewport *> * m_pViewports;
	private: xvector<CDMCrossSlideViewport *> * m_pCrossSlideViewports;
	private: xchainedmap<CUIElement *,IPALDirectManipulationService *> * m_pDMServices;
	private: struct IPALDirectManipulationService * m_pDMCrossSlideService;
	private: XUINT32 m_cCrossSlideContainers;
	private: XUINT32 m_fActivateDM;
	private: void * m_hWnd;
	private: xvector<CWeakRef *> * m_pDMContainersNeedingInitialization;
	private: struct InputMessage * m_pCurrentMsgForDirectManipulationProcessing;
	*/

};